home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / disk / misc / SFSconfig.lha / SFSconfig / SFSconfig.cpp next >
Encoding:
C/C++ Source or Header  |  1999-10-14  |  7.2 KB  |  218 lines

  1. /*  $Id: SFSconfig.cpp 1.2 1999/10/14 17:41:28 helios Exp $
  2.  
  3.     Sets and queries SmartFilesystem parameters
  4. */
  5.  
  6. #include <dos/dos.h>
  7. #include <dos/dosextens.h>
  8. #include <utility/tagitem.h>
  9. #include "fs/packets.h"
  10. #include "fs/query.h"
  11.  
  12. #include <pragmas/dos_pragmas.h>
  13.  
  14. const char *version_str = "\0$VER: SFSconfig 1.2 (14.10.1999) (W) by Martin Steigerwald\r\n";
  15.  
  16. #define TEMPLATE "DEVICE/A,LINES/N,READAHEAD=READAHEADSIZE/N,MAXNAMELENGTH=MAXNAME/N,ACTIVITYFLUSH/N,INACTIVITYFLUSH/N,COPYBACK/S,NOCOPYBACK/S"
  17.  
  18. main()
  19. {
  20.     struct RDArgs *rdargs=NULL;
  21.  
  22.     struct {
  23.         char *device;
  24.         ULONG *lines;
  25.         ULONG *readahead;
  26.         ULONG *maxname;
  27.         ULONG *activityflush;
  28.         ULONG *inactivityflush;
  29.         ULONG copyback;
  30.         ULONG nocopyback;
  31.     } args={NULL};
  32.  
  33.     rdargs = ReadArgs(TEMPLATE, (LONG *)&args, NULL);
  34.  
  35.     if (rdargs == NULL) {
  36.         PrintFault(IoErr(), "SFSconfig");
  37.         return RETURN_ERROR;
  38.     }
  39.     else {
  40.         if (args.copyback!=0 && args.nocopyback!=0) {
  41.             Printf("SFSConfig: Make a decision. Copyback or not? ;-)\n");
  42.             FreeArgs(rdargs);
  43.             return(5L);
  44.         }
  45.  
  46.         struct DosList *dl;
  47.         struct MsgPort *port;
  48.         UBYTE *devname=args.device;
  49.  
  50.         // remove colon from devicename
  51.         while(*devname!=0) {
  52.             if(*devname==':') {
  53.                 *devname=0;
  54.                 break;
  55.             }
  56.             devname++
  57.         }
  58.  
  59.         dl=LockDosList(LDF_DEVICES|LDF_READ);
  60.  
  61.         if ((dl = FindDosEntry(dl, args.device, LDF_DEVICES))!=0) {
  62.             LONG errorcode;
  63.  
  64.             port=dl->dol_Task;
  65.  
  66.             struct TagItem vtags[]={
  67.                 ASQ_VERSION, 0
  68.             };
  69.  
  70.             if ((errorcode = DoPkt(port, ACTION_SFS_QUERY, (LONG)&vtags, 0, 0, 0, 0))!=DOSFALSE) {
  71.                 LONG version, revision;
  72.  
  73.                 version=vtags[0].ti_Data / 65536;
  74.                 revision=vtags[0].ti_Data - (version * 65536);
  75.  
  76.                 // set filename length?
  77.                 if (args.maxname != 0) {
  78.                     Printf("Setting maximum filename length ...\n");
  79.                     struct TagItem stags[]={
  80.                         ASS_MAX_NAME_LENGTH, *args.maxname,
  81.                         TAG_DONE
  82.                     };
  83.                     if ((errorcode = DoPkt(port, ACTION_SFS_SET, (LONG)&stags, 0, 0, 0, 0))==DOSFALSE) {
  84.                         PrintFault(IoErr(), "SFSConfig");
  85.                     }
  86.                 }
  87.  
  88.                 // set maximum activity flush time?
  89.                 if (args.activityflush != 0) {
  90.                     Printf("Setting activity flush timeout ...\n");
  91.                     struct TagItem stags[]={
  92.                         ASS_ACTIVITY_FLUSH_TIMEOUT, *args.activityflush,
  93.                         TAG_DONE
  94.                     };
  95.                     if ((errorcode = DoPkt(port, ACTION_SFS_SET, (LONG)&stags, 0, 0, 0, 0))==DOSFALSE) {
  96.                         PrintFault(IoErr(), "SFSconfig");
  97.                     }
  98.                 }
  99.  
  100.                 // set maximum activity flush time?
  101.                 if (args.inactivityflush != 0) {
  102.                     Printf("Setting inactivity flush timeout ...\n");
  103.                     struct TagItem stags[]={
  104.                         ASS_INACTIVITY_FLUSH_TIMEOUT, *args.inactivityflush,
  105.                         TAG_DONE
  106.                     };
  107.                     if ((errorcode = DoPkt(port, ACTION_SFS_SET, (LONG)&stags, 0, 0, 0, 0))==DOSFALSE) {
  108.                         PrintFault(IoErr(), "SFSConfig");
  109.                     }
  110.                 }
  111.  
  112.  
  113.                 // set the cache?
  114.                 if (args.lines != 0 || args.readahead !=0 || args.copyback != 0 || args.nocopyback !=0) {
  115.                     Printf("Setting cache ...\n");
  116.  
  117.                     struct TagItem ctags[]={
  118.                         ASQ_CACHE_LINES, 0,
  119.                         ASQ_CACHE_READAHEADSIZE, 0,
  120.                         ASQ_CACHE_MODE, 0,
  121.                         TAG_DONE
  122.                     };
  123.  
  124.                     if ((errorcode = DoPkt(port, ACTION_SFS_QUERY, (LONG)&ctags, 0, 0, 0, 0))!=DOSFALSE) {
  125.                         ULONG lines = ctags[0].ti_Data;
  126.                         ULONG readahead = ctags[1].ti_Data;
  127.                         ULONG copyback = ctags[2].ti_Data;
  128.  
  129.                         if (args.lines!=0) {
  130.                             lines = *args.lines;
  131.                         }
  132.                         if (args.readahead!=0) {
  133.                             readahead = *args.readahead;
  134.                         }
  135.                         if (args.copyback!=0) {
  136.                             copyback=1
  137.                         }
  138.                         if (args.nocopyback!=0) {
  139.                             copyback=0
  140.                         }
  141.  
  142.                         if ((errorcode = DoPkt(port, ACTION_SET_CACHE, lines, readahead, copyback, 0, 0))==DOSFALSE) {
  143.                             PrintFault(IoErr(), "SFSconfig");
  144.                         }
  145.  
  146.                     }
  147.                     else {
  148.                         Printf("SFSConfig: Could not query cache parameters!\n");
  149.                         PrintFault(IoErr(), "SFSconfig");
  150.                     } // query cache parameters
  151.                 } // set the cache?
  152.  
  153.                 // show all informations
  154.                 struct TagItem qtags[]={
  155.                     ASQ_IS_CASESENSITIVE, 0,
  156.                     ASQ_HAS_RECYCLED, 0,
  157.                     ASQ_CACHE_LINES, 0,
  158.                     ASQ_CACHE_READAHEADSIZE, 0,
  159.                     ASQ_CACHE_MODE, 0,
  160.                     TAG_DONE
  161.                 };
  162.  
  163.                 Printf("Devicename:     %s:\n", args.device);
  164.  
  165.                 Printf("SFS version:    %ld.%ld\n", version, revision);
  166.  
  167.                 if ((errorcode = DoPkt(port, ACTION_SFS_QUERY, (LONG)&qtags, 0, 0, 0, 0))!=DOSFALSE) {
  168.  
  169.                     Printf("Cache:          %ld lines * %ld bytes readahead size = %ld bytes.\n",
  170.                         qtags[2].ti_Data, qtags[3].ti_Data, qtags[2].ti_Data * qtags[3].ti_Data);
  171.  
  172.                     Printf("                Copyback mode");
  173.  
  174.                     if (qtags[4].ti_Data==0) {
  175.                         Printf(" disabled.\n");
  176.                     }
  177.                     else {
  178.                         Printf(" enabled.\n");
  179.                     }
  180.  
  181.                     Printf("Fixed options:  ");
  182.  
  183.                     if (qtags[0].ti_Data!=0) {
  184.                         Printf("(case sensitive) ");
  185.                     }
  186.                     else {
  187.                         Printf("(not case-sensitive) ");
  188.                     }
  189.  
  190.                     if (qtags[1].ti_Data!=0) {
  191.                         Printf("(recycled)");
  192.                     }
  193.                     else {
  194.                         Printf("(no recycled)");
  195.                     }
  196.  
  197.                     Printf("\n");
  198.                 }
  199.                 else {
  200.                     Printf("SFSconfig: Second SFSQuery failed!\n");
  201.                     PrintFault(IoErr(), "SFSconfig");
  202.                 }
  203.             }
  204.             else {
  205.                 Printf("SFSconfig: SFSQUERY failed. Maybe no SFS device?\n");
  206.                 PrintFault(IoErr(), "SFSconfig");
  207.             }
  208.         }
  209.         else {
  210.             Printf("Couldn't find device: '%s:'\n", args.device);
  211.         }
  212.         UnLockDosList(LDF_DEVICES|LDF_READ);
  213.  
  214.         FreeArgs(rdargs);
  215.     } // ReadArgs
  216. }
  217.  
  218.